< previous page page_133 next page >

Page 133
Puzzle 30
File Operations, Part 1
Every Windows user is familiar with the types of file operations supported by Windows Explorer. Not Internet Explorer, mind you (though it is becoming increasingly difficult to tell the difference between them), but the main Windows interface. Windows Explorer makes it easy to drag files from one directory to anothermoving them, copying them, deleting them, and so on. We've all seen the dialog boxes that prompt for confirmation, offer feedback that an operation is in progress, or report errors that occur.
There's a lot of file management functionality in Windows Explorer, and we all work with it every day. But what many Windows programmers do not realize is that most of this functionality is packed into one small function called SHFileOperation.
This simple function, with a single structure parameter, is defined as follows in the Win32 SDK:
WINSHELLAPI int WINAPI SHFileOperation(
    LPSHFILEOPSTRUCT lpFileOp
   );
The Visual Basic declaration is easy:
Private Declare Function SHFileOperation Lib "shell32.dll" _
Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
How can one function perform all those file operations? Simpleall the parameters are crammed into the SHFILEOPSTRUCT structure, which is defined in the Win32 SDK as follows:
typedef struct _SHFILEOPSTRUCT { // shfos
    HWND         hwnd;
    UINT         wFunc;
    LPCSTR       pFrom;
    LPCSTR       pTo;
    FILEOP_FLAGS fFlags;

 
< previous page page_133 next page >